package menu

import (
	"context"
	"trusteva/app/rbac/model"

	"trusteva/app/rbac/internal/svc"
	"trusteva/app/rbac/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MenuUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMenuUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuUpdateLogic {
	return &MenuUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MenuUpdateLogic) MenuUpdate(req *types.MenuUpdateRo) (resp *types.BaseRsp, err error) {
	err = l.svcCtx.DB.WithContext(l.ctx).Where("Id=?", req.MenuId).
		Select("Name", "Typ", "Memo", "ParentId", "Status", "Sequence", "Path").
		Updates(&model.MenuConfig{
			Name:     req.Name,
			Typ:      req.Typ,
			Memo:     req.Memo,
			ParentId: req.ParentId,
			Status:   model.LimitStatus(req.Status),
			Sequence: req.Sequence,
			Path:     req.Path,
		}).Error
	return
}
